<?
function parcurgere($id)
{
	$sql_curent=mysql_query("select * from locatii where id='".$id."'");
	if(mysql_num_rows($sql_curent)>0)
		{
			$curent=mysql_fetch_array($sql_curent);
$ret='<li><a href="#" onclick="document.getElementById(\'loc\').value='.$id.';document.getElementById(\'nume_locatie\').value=\''.$curent['name'].'\'" >'.$curent['name'].'</a>'; 
			//$ret='<li><a href="locatii.php?id='.$id.'">'.$curent['name'].'</a>'; 
			
		}
	$sql_copii=mysql_query("select id from locatii where id_parent='".$id."'");
	$c=mysql_num_rows($sql_copii);
	if($c>0)
		$ret.='<ul>';
	while(list($copil)=mysql_fetch_array($sql_copii))
		{
			$ret.=parcurgere($copil);
		}
	if($c>0)
		$ret.='</ul>';
	if(mysql_num_rows($sql_curent)>0)
		{
		$ret.='</li>';
		}
	return $ret;
}


function parcurgere_tot($id,$lvl)
{   
	$sql_curent=mysql_query("select * from locatii where id='".$id."'");
	if (mysql_num_rows($sql_curent)>0)
	 {
	 	$curent=mysql_fetch_array($sql_curent);
	   $ret='<li><a href="adauga_oferta.php?loc='.$id.'">'.$curent['name'].'</a>'; 
		 
	}
	$sql_copii=mysql_query("select id from locatii where id_parent='".$id."'");
	$c=mysql_num_rows($sql_copii);
	if($c>0)
		$ret.='<ul>';
	while(list($copil)=mysql_fetch_array($sql_copii))
	{
		$ret.=parcurgere_tot($copil,$lvl+1);
	}
	if($c>0)
		$ret.='</ul>';
	if(mysql_num_rows($sql_curent)>0)
		{
		$ret.='</li>';
		}
	return $ret; 
}

function stergere_arbore($id)
{   
	$sql_copii=mysql_query("select id from locatii where id_parent='".$id."' ");
	while(list($copil)=mysql_fetch_array($sql_copii))
	{	
	stergere_arbore($copil);
	}
	mysql_query("delete from locatii where id='".$id."' ");
}

?>